package com.qf.service.impl;

import com.qf.borrower.Borrower;
import com.qf.dao.BorrowerRepository;
import com.qf.service.BorrowerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class BorrowerServiceImpl implements BorrowerService {

    @Autowired
    private BorrowerRepository borrowerRepository;

    @Override
    public List<Borrower> findAll() {
        return borrowerRepository.findAll();
    }

    @Override
    public Borrower findById(Integer id) {
        return borrowerRepository.findById(id).get();
    }

    @Override
    public String saveOrUpdate(Borrower borrower) {
        Borrower borrower1 = borrowerRepository.saveAndFlush(borrower);
        System.out.println(borrower1+"===========");
        if (borrower1!=null){
            return "success";
        }else{
            return "fail";
        }
    }

    @Override
    public String deleteById(Integer id) {
        try {
            borrowerRepository.deleteById(id);
            return "success";
        }catch (Exception e){
            System.out.println(e.getMessage());
            return "fail";
        }
    }
}
